<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>msg:{{msg}}</p>
        <input type="text" v-model="msg">
        <hr>
        <p>aaa:{{a}}</p>
        <p>{{getA}}</p>
        <hr>
        <comp-a></comp-a>
    </div>
    <hr>
    <div id="root">
        <p>msg:{{msg}}</p>
        <input type="text" v-model="msg">
    </div>
    <template id="child">
        <div>
            <p>msg:{{msg}}</p>
            <input type="text" v-model="msg">
        </div>
    </template>
</body>
<script>
    Vue.prototype.$state=Vue.observable({
        msg:"林志颖",
        user:{
            name:"iboy",
            age:20
        }
    })
    const mixinState={
        computed:{
            msg:{
                get(){
                    return this.$state.msg;
                },
                set(nv){
                    // console.log(this);
                    this.$state.msg=nv;
                }
            },
            user:{
                get(){
                    return this.$state.user;
                },
                set(nv){
                    this.$state.user=nv;
                }
            }
        }
    }
    new Vue({
        mixins:[mixinState],
        el:"#app",
        components:{
            compA:{
                mixins:[mixinState],
                template:"#child"
            }
        },
        data:{
            a:"哈哈哈"
        },
        computed:{
            getA(){
                return this.a+1;
            }
        },
        mounted(){
            console.log(this);
            // console.log(this.$state);
        }
    });
    new Vue({
        el:"#root",
        mixins:[mixinState]
    })
</script>
</html>